package ru.evga.inse.server.gwt.admin.client.menu;


public abstract class AdminMenuProcessor<T>
{
    private final T m_defaultValue;

    private T m_result;

    /**
     * Create an instance with a null default value.
     */
    public AdminMenuProcessor()
    {
        m_defaultValue = null;
    }

    /**
     * Create an instance with the given default value.
     * 
     * @param the
     *            value that will be returned by {@link #process} if
     *            {@link #setResult} is not called.
     */
    public AdminMenuProcessor(T defaultValue)
    {
        this.m_defaultValue = defaultValue;
    }

    public abstract void handleCity();

    public abstract void handleStreet();

    public T process(AdminMenuItem item)
    {
        setResult(m_defaultValue);
        if (AdminMenuItem.CITY == item)
        {
            handleCity();
        }
        else if (AdminMenuItem.STREET == item)
        {
            handleStreet();
        }
        return m_result;
    }

    /**
     * Set the value to return from a call to {@link #process(Class)} or
     * {@link #process(Object)}.
     * 
     * @param result
     *            the value to return
     */
    protected void setResult(T result)
    {
        this.m_result = result;
    }
}
